package com.ruoyi.bantong.controller;

import com.ruoyi.bantong.domain.BtArticle;
import com.ruoyi.bantong.service.IBtArticleService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章Controller
 * 
 * @author laohei
 * @date 2021-01-24
 */
@RestController
@RequestMapping("/bantong/article")
public class BtArticleController extends BaseController
{
    @Autowired
    private IBtArticleService btArticleService;

    /**
     * 查询文章列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(BtArticle btArticle)
    {
        startPage();
        List<BtArticle> list = btArticleService.selectBtArticleList(btArticle);
        return getDataTable(list);
    }

    /**
     * 导出文章列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:article:export')")
    @Log(title = "文章", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BtArticle btArticle)
    {
        List<BtArticle> list = btArticleService.selectBtArticleList(btArticle);
        ExcelUtil<BtArticle> util = new ExcelUtil<BtArticle>(BtArticle.class);
        return util.exportExcel(list, "article");
    }

    /**
     * 获取文章详细信息
     */
    //@PreAuthorize("@ss.hasPermi('bantong:article:query')")
    @GetMapping(value = "/{artId}")
    public AjaxResult getInfo(@PathVariable("artId") Integer artId)
    {
        return AjaxResult.success(btArticleService.selectBtArticleById(artId));
    }

    /**
     * 新增文章
     */
    //@PreAuthorize("@ss.hasPermi('bantong:article:add')")
    @Log(title = "文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BtArticle btArticle)
    {
        return toAjax(btArticleService.insertBtArticle(btArticle));
    }

    /**
     * 修改文章
     */
    //@PreAuthorize("@ss.hasPermi('bantong:article:edit')")
    @Log(title = "文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BtArticle btArticle)
    {
        return toAjax(btArticleService.updateBtArticle(btArticle));
    }

    /**
     * 删除文章
     */
    //@PreAuthorize("@ss.hasPermi('bantong:article:remove')")
    @Log(title = "文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{artIds}")
    public AjaxResult remove(@PathVariable Integer[] artIds)
    {
        return toAjax(btArticleService.deleteBtArticleByIds(artIds));
    }

    /**
     * 新增文章 播放量
     */
    //@PreAuthorize("@ss.hasPermi('bantong:article:add')")
    @Log(title = "文章", businessType = BusinessType.INSERT)
    @PostMapping("/addView/{artId}")
    public AjaxResult addArticleView(@PathVariable("artId") Integer artId)
    {
        return toAjax(btArticleService.addArticleView(artId));
    }
}
